package com.bookmanage.dao;

import com.bookmanage.utils.DBUitls;

import java.sql.*;

public class Conn1 {

    public static boolean check(String username, String password) {
        boolean checkOK = false;
        try {
            Connection conn = DBUitls.getConn();

            String sql = "select * from admininfo where username=? and password=?";
            //预处理编译sql
            PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
            //设置数据库的两个参数
            pst.setString(1, username);
            pst.setString(2, password);
            ResultSet rs = (ResultSet) pst.executeQuery();
            if (conn != null) {
                // System.out.print("success!");
                if (rs.next()) {
                    //查询到就true
                    checkOK = true;

                    conn.close();
                } else {

                    checkOK = false;

                }
            } else {
                System.out.println("数据库连接失败");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return checkOK;
    }
}
